﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using web.BLL;

namespace web.Controllers
{
    public class SiteController : BaseController
    {
        //
        // GET: /Site/

        public ActionResult info()
        {
            return View();
        }
        public ActionResult baner()
        {
            return View();
        }
        public ActionResult userlist()
        {
            return View();
        }
        public ActionResult loglist()
        {
            return View();
        }

        public JsonResult savesite()
        {

            int id = RequestQ("id") != "" ? Convert.ToInt32(RequestQ("id")) : 0;
            //编辑
            return Json(sitebll.savesite(id));
        }

        public JsonResult getsiteinfo()
        {
            int id = RequestQ("id") != "" ? Convert.ToInt32(RequestQ("id")) : 0;
            //编辑
            return Json(sitebll.getsite(id));

        }

         public ActionResult getloglist()
        {
           
            string keyword = RequestQ("keyword");
            int start = RequestQ("start") != "" ? Convert.ToInt32(RequestQ("start")) : 0;
            int limit = RequestQ("limit") != "" ? Convert.ToInt32(RequestQ("limit")) : 20;
            return Content(sitebll.getloglist(keyword,start,limit));
        }

         public JsonResult batchdellog()
        {
            string ids = RequestQ("ids");

            try
            {
                sitebll.dellogs(ids);
                return Json("{\"success\":true,\"msg\":\"删除成功\"}");
            }
            catch
            {

                return Json("{\"success\":false,\"msg\":\"删除失败\"}");
            }

        }

         #region banner

         public ActionResult addbaner() {
             ViewBag.id = RequestQ("id") != "" ? Convert.ToInt32(RequestQ("id")) : 0;
             return View();
         }

         public ActionResult getbanerlist()
         {
             int start = RequestQ("start") != "" ? Convert.ToInt32(RequestQ("start")) : 0;
             int limit = RequestQ("limit") != "" ? Convert.ToInt32(RequestQ("limit")) : 20;
             return Content(sitebll.getbanerlist(start, limit));
         }
         public JsonResult batchdelbaner()
         {
             string ids = RequestQ("ids");

             try
             {
                 sitebll.delbaners(ids);
                 return Json("{\"success\":true,\"msg\":\"删除成功\"}");
             }
             catch
             {

                 return Json("{\"success\":false,\"msg\":\"删除失败\"}");
             }
         }

         public JsonResult savebaner()
         {

             int id = RequestQ("id") != "" ? Convert.ToInt32(RequestQ("id")) : 0;
             //编辑
             return Json(sitebll.savebaner(id));
         }
         public JsonResult getbanerinfo()
        {
            int id = RequestQ("id") != "" ? Convert.ToInt32(RequestQ("id")) : 0;
            //编辑
            return Json(sitebll.getbaner(id));

        }
       #endregion



         #region user

         public ActionResult adduser()
         {
             ViewBag.id = RequestQ("id") != "" ? Convert.ToInt32(RequestQ("id")) : 0;
             return View();
         }

         public ActionResult getuserlist()
         {
             int start = RequestQ("start") != "" ? Convert.ToInt32(RequestQ("start")) : 0;
             int limit = RequestQ("limit") != "" ? Convert.ToInt32(RequestQ("limit")) : 20;
             return Content(sitebll.getuserlist(start, limit));
         }
         public JsonResult batchdeluser()
         {
             string ids = RequestQ("ids");

             try
             {
                 sitebll.delusers(ids);
                 return Json("{\"success\":true,\"msg\":\"删除成功\"}");
             }
             catch
             {

                 return Json("{\"success\":false,\"msg\":\"删除失败\"}");
             }
         }

         public JsonResult saveuser()
         {

             int id = RequestQ("id") != "" ? Convert.ToInt32(RequestQ("id")) : 0;
             if (id == 0)
             {
                 string loginname = RequestQ("loginname");
                 if (!sitebll.isexit(loginname))
                 {
                     return Json("{\"success\":false,\"msg\":\"保存失败,登录名已经存在！\"}");
                 }
             }
             //编辑
             return Json(sitebll.saveuser(id));
         }
         public JsonResult getuserinfo()
         {
             int id = RequestQ("id") != "" ? Convert.ToInt32(RequestQ("id")) : 0;
             //编辑
             return Json(sitebll.getuser(id));

         }
         #endregion


    }
}
